<?php

namespace App\Admin\Controllers\Record;

use App\Http\Controllers\Controller;
use App\Admin\Models\Record\MemberTraining;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Widgets\Table;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use DB;

class MemberTrainingController extends Controller
{
	use HasResourceActions;
	
    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('客户情况跟踪表')
            ->description('列表')
            ->body($this->grid());
    }
    
    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('流水记录')
            ->description('详细')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('')
            ->description('编辑')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('客情效果跟踪')
            ->description('创建')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new MemberTraining);
        $grid->model()->where('sId', '=', Admin::user()->sId);
        $grid->rmrId('ID');
        $grid->rmrRecord('建档');
        $grid->rmrName('客户姓名');
        $grid->rmrPhone('电话');
        $grid->rmrAddress('地址');
        $grid->rmrAge('年龄');
        $grid->rmrCategory('类别');
        $grid->rmrPeriod('六期');
        $grid->rmrStatsLevel('七级');
        $grid->rmrCosmetologist('美容师');
        $grid->rmrComeTime('到店时间');
        $grid->rmrMemberCondition('客户身体问题');
        $grid->rmrBeddingItem('铺垫项目');
        $grid->rmrSolution('问题处理方法');
        $grid->rmrResult('反馈结果');
        $grid->rmrDealMoney('成交金额');
        $grid->rmrRemark('顾问点评');
        $grid->createTime('创建时间');
        $grid->createUser('创建人');

		$grid->filter(function($filter){

		    // 去掉默认的id过滤器
		    $filter->disableIdFilter();

		});
		
		$grid->actions(function ($actions) {
			
		    $actions->disableDelete();
		    $actions->disableEdit();
			$actions->disableView();
		});

		$grid->filter(function($filter){

		    // 去掉默认的id过滤器
		    $filter->disableIdFilter();
		    

		});
		
		// 禁用新增按钮
//		$grid->disableCreateButton();

		// 默认展开筛选框
		$grid->expandFilter();
		
		// 禁用行选择checkbox
		$grid->disableRowSelector();
		
		// 禁用导出
		$grid->disableExport();
        return $grid;
    }
    
    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
    	$walletTrade = new walletTrade();
        $show = new Show($walletTrade->findOrFail($id));

        //$show->spId('ID');
        $show->spType('参数类型');
        $show->spKey('参数名称');
        $show->spValue('参数值');
        $show->spMemo('参数备注');
        $show->spSort('参数排序');
		$show->panel()
			->tools(function ($tools) {
//				$tools->disableEdit();
//				$tools->disableList();
				$tools->disableDelete();
		});;
        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::Form(MemberTraining::class, function (Form $form) {
			
			$now = date('YmdHis', time());
			
			$form->text('rmrRecord', '建档');
			$form->text('rmrName', '客户姓名');
			$form->mobile('rmrPhone', '电话')->rules('required|regex:/^[1][0-9]{10}$/', [
        									'required' => '请填写手机号',
        									'regex' => '手机号格式不正确'
        									])
        									->attribute(['style' => 'width: 25%']);
			$form->text('rmrAddress', '地址');
			$form->number('rmrAge', '年龄');
			$rmrCategory = array();
			$rmrCategory['5K'] = '5K';
			$rmrCategory['4K'] = '4K';
			$rmrCategory['1K-4k'] = '1K-4k';
			$rmrCategory['5B-1K'] = '5B-1K';
			$form->select('rmrCategory', '类别')->options($rmrCategory);
			$rmrPeriod = array();
			$rmrPeriod['铺垫期'] = '铺垫期';
			$rmrPeriod['感动期'] = '感动期';
			$rmrPeriod['销售期'] = '销售期';
			$rmrPeriod['服务期'] = '服务期';
			$rmrPeriod['提升期'] = '提升期';
			$rmrPeriod['稳定期'] = '稳定期';
			$form->select('rmrPeriod', '六期')->options($rmrPeriod);
			$rmrStatsLevel = array();
			$rmrStatsLevel['初入会员'] = '初入会员';
			$rmrStatsLevel['成熟会员'] = '成熟会员';
			$rmrStatsLevel['忠诚会员'] = '忠诚会员';
			$rmrStatsLevel['榜样会员'] = '榜样会员';
			$rmrStatsLevel['问题会员'] = '问题会员';
			$rmrStatsLevel['淘汰会员'] = '淘汰会员';
			$rmrStatsLevel['沉睡会员'] = '沉睡会员';
			$form->select('rmrStatsLevel', '七级')->options($rmrStatsLevel);
			$form->text('rmrCosmetologist', '美容师');
			$form->date('rmrComeTime', '到店时间');
			$form->text('rmrMemberCondition', '客户身体问题');
			$form->text('rmrBeddingItem', '铺垫项目');
			$form->text('rmrSolution', '问题处理方案');
			$form->text('rmrResult', '反馈结果');
			$form->number('rmrDealMoney', '成交金额');
			$form->text('rmrRemark', '顾问点评');
			
			$form->saved(function (Form $form) {
			
			    $rmrId = $form->model()->rmrId;
				DB::table('record_member_training')->where('rmrId', $rmrId)->update(['createUser'=> Admin::user()->name, 'sId' => $sId = Admin::user()->sId]);
			});
			
            $form->tools(function (Form\Tools $tools) {

			    // 去掉`列表`按钮
//			    $tools->disableList();
				
			    // 去掉`删除`按钮
			    $tools->disableDelete();
			
			    // 去掉`查看`按钮
			    $tools->disableView();
			
			    // 添加一个按钮, 参数可以是字符串, 或者实现了Renderable或Htmlable接口的对象实例
//			    $tools->add('<a class="btn btn-sm btn-danger"><i class="fa fa-trash"></i>&nbsp;&nbsp;delete</a>');
			});
			
			$form->footer(function ($footer) {

//			    // 去掉`重置`按钮
//			    $footer->disableReset();
//			
//			    // 去掉`提交`按钮
//			    $footer->disableSubmit();
			
			    // 去掉`查看`checkbox
			    $footer->disableViewCheck();
			
			    // 去掉`继续编辑`checkbox
			    $footer->disableEditingCheck();
			
			    // 去掉`继续创建`checkbox
			    $footer->disableCreatingCheck();
			
			});
        });
    }
}
